/**
 * Created by Administrator on 2019/5/18/018.
 */
import CZML_GENERALTOOLS_CLASS from "./../main/CZML_GENERALTOOLS_CLASS.js"

class CZML_Prism {
  constructor(viewer, id, name, DataStartTime, posA, posB, posC, posD, number, PrismColor, MarkerVisible, height, ReferenceFrame) {
    this._viewer = viewer
    this.id = id
    this.name = name
    this.DataStartTime = DataStartTime
    this.posA = posA
    this.posB = posB
    this.posC = posC
    this.posD = posD
    this.number = number
    this.PrismColor = PrismColor
    this.MarkerVisible = MarkerVisible
    this.height = height
    this.ReferenceFrame = ReferenceFrame
    this.posAid = id + "-to-Prism-posA"
    this.posBid = id + "-to-Prism-posB"
    this.posCid = id + "-to-Prism-posC"
    this.posDid = id + "-to-Prism-posD"
    this.CZML_AddPrism()
  }

  CZML_AddPrism() {
    const sDataStartTime = CZML_GENERALTOOLS_CLASS.Utcg2ISO8601TimeTransformation(this.DataStartTime)
    const pointA = {
      id: this.posAid,
      availability: CZML_GENERALTOOLS_CLASS.HEU_ScenarioTime,
      show: true,
      label: {
        fillColor: {
          rgba: this.PrismColor
        },
        font: "11pt Lucida Console",
        horizontalOrigin: "CENTER",
        pixelOffset: {
          cartesian2: [30, 10]
        },
        show: this.MarkerVisible,
        style: "FILL_AND_OUTLINE",
        text: this.name,
        verticalOrigin: "CENTER"
      },
      position: {
        interpolationAlgorithm: "LAGRANGE",
        interpolationDegree: 5,
        referenceFrame: this.ReferenceFrame,
        epoch: sDataStartTime,
        cartographicDegrees: this.posA
      }
    }
    const pointB = {
      id: this.posBid,
      availability: CZML_GENERALTOOLS_CLASS.HEU_ScenarioTime,
      show: true,
      position: {
        interpolationAlgorithm: "LAGRANGE",
        interpolationDegree: 5,
        referenceFrame: this.ReferenceFrame,
        epoch: sDataStartTime,
        cartographicDegrees: this.posB
      }
    }
    const pointC = {
      id: this.posCid,
      availability: CZML_GENERALTOOLS_CLASS.HEU_ScenarioTime,
      show: true,
      position: {
        interpolationAlgorithm: "LAGRANGE",
        interpolationDegree: 5,
        referenceFrame: this.ReferenceFrame,
        epoch: sDataStartTime,
        cartographicDegrees: this.posC
      }
    }
    const pointD = {
      id: this.posDid,
      availability: CZML_GENERALTOOLS_CLASS.HEU_ScenarioTime,
      show: true,
      position: {
        interpolationAlgorithm: "LAGRANGE",
        interpolationDegree: 5,
        referenceFrame: this.ReferenceFrame,
        epoch: sDataStartTime,
        cartographicDegrees: this.posD
      }
    }
    const ret1 = CZML_GENERALTOOLS_CLASS.InsertModelObjectInformation(this.posAid, pointA, true)
    const ret2 = CZML_GENERALTOOLS_CLASS.InsertModelObjectInformation(this.posBid, pointB, true)
    const ret3 = CZML_GENERALTOOLS_CLASS.InsertModelObjectInformation(this.posCid, pointC, true)
    const ret4 = CZML_GENERALTOOLS_CLASS.InsertModelObjectInformation(this.posDid, pointD, true)
    const PosARef = this.posAid + "#position"
    const PosBRef = this.posBid + "#position"
    const PosCRef = this.posCid + "#position"
    const PosDRef = this.posDid + "#position"
    const Prism = {
      id: this.id,
      name: this.name,
      availability: CZML_GENERALTOOLS_CLASS.HEU_ScenarioTime,
      polygon: {
        show: [
          {
            interval: CZML_GENERALTOOLS_CLASS.HEU_ScenarioTime,
            boolean: true
          }
        ],
        material: {
          solidColor: {
            color: {
              rgba: this.PrismColor
            }
          }
        },
        perPositionHeight: true,
        closeTop: true,
        closeBottom: true,
        positions: {
          references: [PosARef, PosBRef, PosCRef]
        },
        extrudedHeight: this.height
      }
    }
    if (this.PrismColor === 1) {
      Prism.polyline.material = {
        grid: {
          color: {
            rgba: this.PrismColor
          }
        }
      }
    }
    if (this.number === 4) {
      Prism.polygon.positions = {
        references: [PosARef, PosBRef, PosCRef, PosDRef]
      }
    }
    // 插入该数据对象
    const ret = CZML_GENERALTOOLS_CLASS.InsertModelObjectInformation(this.id, Prism, true)
    // 上图
    CZML_GENERALTOOLS_CLASS.Upper(this._viewer)
    return ret
  }
}

export default CZML_Prism
